package main

import (
	_ "bootstrap/config-apollo/apollo"
	_ "bootstrap/config-yaml/yaml"
	"bootstrap/global/config"
	"fmt"
)

type Bootstrap struct {
	Gin    Gin    `name:"gin"`
	Server Server `name:"server"`
}

type Gin struct {
	Application struct {
		Name string `name:"name"`
	} `name:"application"`
	Redis Redis `name:"redis"`
}

type Redis struct {
	Host     string `name:"host"`
	Port     int    `name:"port"`
	Password string `name:"password"`
}

type Server struct {
	Port int `name:"port"`
}

func main() {
	if err := config.InitGlobalInstance("yaml", "resource/app.yaml"); err != nil {
		fmt.Println(err)
		return
	}
	if err := config.InitGlobalInstance("apollo", ""); err != nil {
		fmt.Println(err)
		return
	}
	name, ok := config.Get("gin.application.name")
	if ok {
		fmt.Printf("get gin.application.name: %v \n", name)
	} else {
		fmt.Println("not found gin.application.name")
	}

	var bootstrap Bootstrap
	if err := config.Resolve("", &bootstrap); err != nil {
		fmt.Printf("resolve bootstrap error, %v\n", err)
	} else {
		fmt.Printf("resolve bootstrap: %v\n", bootstrap)
	}

	var redis Redis
	if err := config.Resolve("gin.redis", &redis); err != nil {
		fmt.Printf("resolve redis error, %v\n", err)
	} else {
		fmt.Printf("resolve redis: %v\n", redis)
	}
}
